/*
 * Copyright   2000   The Regents of the University of California
 * All Rights Reserved
 * 
 * Permission to use, copy, modify and distribute any part of Simgrid/SG
 * for educational, research and non-profit purposes, without fee, and
 * without a written agreement is hereby granted, provided that the above
 * copyright notice, this paragraph and the following three paragraphs
 * appear in all copies.
 * 
 * Those desiring to incorporate this Simgrid/SG into commercial
 * products or use for commercial purposes should contact the Technology
 * Transfer & Intellectual Property Services, University of California,
 * San Diego, 9500 Gilman Drive, Mail Code 0910, La Jolla, CA 92093-0910,
 * Ph: (858) 534-5815, FAX: (858) 534-7345, E-MAIL:invent@ucsd.edu.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
 * INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS Simgrid/SG,
 * EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.  
 * 
 * THE Simgrid/SG PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
 * UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  THE UNIVERSITY OF
 * CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY
 * KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
 * PURPOSE, OR THAT THE USE OF THE Simgrid/SG WILL NOT INFRINGE ANY
 * PATENT, TRADEMARK OR OTHER RIGHTS.
 */

#ifndef SG_PROTOTYPES_H
#define SG_PROTOTYPES_H

/* This file contains all the crap that's not in simgrid.h */

#include <stdlib.h>

#include "simgrid.h"

/******************************************/
/* non-API TASK FUNCTIONS                 */
/******************************************/
int SG_taskHash(SG_Task);
void SG_freeTask(SG_Task task);
long double SG_integrateTraceWithOffset(SG_Trace trace, long double a,
				   long double b, long double offset);
long double SG_integrateTrace(SG_Trace trace, long double a, long double b);
long double SG_integrateTraceSimple(SG_Trace trace, long double a, long double b);
long double SG_solveTraceIntegralWithOffset(SG_Trace trace, long double a,
				       long double amount, long double offset);
long double SG_solveTraceIntegral(SG_Trace trace, long double a, long double amount);
long double SG_solveTraceIntegralSimple(SG_Trace trace, long double a,
				   long double amount);
long double SG_solveTraceIntegralSomewhatSimple(SG_Trace trace, long double a,
					   long double amount);
long double SG_getTraceValueWithOffset(SG_Trace trace, long double ttime,
				  long double offset);
long double SG_getTraceValue(SG_Trace trace, long double ttime);

/* failure code */
long double SG_evaluateFailureTrace(SG_Trace trace,long double a,long double b);
long double SG_getTimeToFailure(SG_Trace trace);
long double SG_getTraceCDF(SG_Trace trace,long double ttime);


/******************************************/
/* non-API RESOURCE FUNCTIONS             */
/******************************************/
int SG_resourceHash(SG_Resource);
void SG_freeResource(SG_Resource resource);
int SG_resourcePerformanceIsConstant(SG_Resource resource);

/******************************************/
/* non-API TRACE and TIMESERIES FUNCTIONS */
/******************************************/
int SG_traceHash(SG_Trace);
void SG_freeTrace(SG_Trace trace);
SG_Trace SG_newTrace(SG_levelmode_t level_mode, SG_trace_t type,
		     const char *filename, long double value, long double spacing);
SG_Trace SG_lookupTrace(SG_trace_t type, const char *filename, long double value);

void SG_freeTimeSeries(SG_TimeSeries series);
SG_TimeSeries SG_getTimeSeriesFromFile(const char *filename, long double spacing);
SG_TimeSeries SG_coarsenTimeSeries(SG_TimeSeries series, int factor);

/******************************************/
/* non-API PREDICTION FUNCTIONS           */
/******************************************/
long double SG_getPerfectPrediction(SG_Resource, long double ttime, long double amount);

void SG_computeRandomNumberIndex(SG_prediction_t type,
				 long double attribute,
				 long double (*error) (long double time,
						  long double amount,
						  long double attribute),
				 SG_Resource resource,
				 long double when, long double amount);
/*int SG_rand();*/
void SG_initializeRandomNumberArray(void);

/*****************************************/
/* non-API TCP SIMULATION FUNCTIONS      */
/*****************************************/
long double runTCPTransfers(long double how_long);
SG_Resource copyTCPLink(SG_Resource llink);

/******************************************/
/* Memory management functions and macros */
/******************************************/
void *SG_my_calloc(size_t, size_t);
void *SG_my_realloc(void *ptr, size_t size);
void SG_free(void *ptr);
char *SG_my_strdup(const char *);

/*******************************************/
/* Functions that have not made it to the  */
/* public API yet                          */
/*******************************************/
SG_EndToEndTransfer SG_createEndToEndTransfer(char *name,
					      int nb_links,
					      SG_Resource * links,
					      long double data_size,
					      long double packet_size,
					      void *metadata);

void SG_scheduleEndToEndTransfer(SG_EndToEndTransfer t);
void SG_finalizeEndToEndTransfer(SG_EndToEndTransfer t);
SG_taskstate_t SG_getEndToEndTransferState(SG_EndToEndTransfer t);
SG_Task SG_getEndToEndFirst(SG_EndToEndTransfer t);
SG_Task SG_getEndToEndLast(SG_EndToEndTransfer t);

#endif				/* SG_PROTOTYPES_H */
